package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.commons.ResponseResult;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.service.ClazzService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 课工场
 * @date 2024/5/8
 * @description
 */
@RestController
@RequestMapping("clazz")
public class ClazzController {

    @Resource
    private ClazzService clazzService;

    //  班级列表
    @GetMapping
    public ResponseResult  clazzList(){
        return clazzService.clazzList();
    }

    //  根据id获取班级信息
    @GetMapping("{id}")
    public Clazz getOneClazz(@PathVariable("id") Integer id){
        return clazzService.getById(id);
    }

    //  删除班级信息
    @DeleteMapping("{id}")
    public ResponseResult  deleteClazz(@PathVariable("id") Integer id){
        clazzService.removeById(id);
        return ResponseResult.success().message("班级信息删除成功");
    }

    // 添加班级信息
    @PostMapping
    public ResponseResult  addClazz(@RequestParam("file") MultipartFile file,String name,Integer tagId){

        return clazzService.addClazz(file,name,tagId);
    }
}
